import Vue from 'vue'
import Router from 'vue-router'
import Login from "@/view/Login";

Vue.use(Router)

export const constantRouterMap = [{
    path: '/',
    component:  ()=> import("@/view/collect-information"),
},    {
    path: '/back',
    component: ()=> import("@/view/back"),
    redirect: "/back/userMsg",
    children:[
        {
            path: 'userMsg',
            component: ()=> import("@/view/userMsg"),
        },
        {
            path: 'world',
            component: ()=> import("@/view/world"),
        },
    ]
},
    {
        path: '/login',
        component: ()=> import("@/view/Login"),
    },
    {
        path: '/inquire',
        component: ()=> import("@/view/inquire"),
    },
    {
        path: '*',
        name: 'NotFound',
        component: () => import('@/components/not-found'),
        meta: {
            title: '404页面',
            httpStatus: 404
        }
    }
]


const router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// router.beforeEach((to, from, next) => {
//     if (isValidRoute) {
//         next(); // Route exists, continue navigating to the target route
//     } else {
//         if (to.meta && to.meta.title) {
//             document.title = to.meta.title;
//             if (to.meta.httpStatus) {
//                 // 设置HTTP状态码，注意浏览器可能不允许你修改404状态码
//                 // 如果你的应用是服务端渲染的，你应该在服务端设置状态码
//                 router.app.$ssrContext && (router.app.$ssrContext.status = to.meta.httpStatus);
//             }
//         }
//         next({name:'NotFound'});
//         // window.location.href = 'https://contedu.hnzyfy.com/api/404';
//     }
// });

export default router

